package com.mapper;

import com.entity.neo4j.CourseNode;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.data.neo4j.repository.query.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface CourseNeoRepository extends Neo4jRepository<CourseNode, Long> {
    // 通过课程名称查找课程节点
    @Query("MATCH (n:CourseNode) where n.courseName = {name} return n")
    List<CourseNode> getCoursesNodeByCourseName(@Param("name") String name);

    // 通过关系名称查找课程节点
    @Query("MATCH p=()-[r:relation]->() \n" +
            "where r.relation = {name}\n" +
            "RETURN p")
    List<CourseNode> getCoursesNodeByRelation(@Param("name") String name);

    // 创建两个课程节点之间的关系
//    @Query("match (a:CourseNode),(b:CourseNode)\n" +
//            "where a.courseName=#{fromNode} and b.courseName = {2}\n" +
//            "create (a)-[relation:{1}]->(b)")
    @Query("match (n:CourseNode{courseName:{fromNode}}),(m:CourseNode{courseName:{toNode}})" +
            "create (n)-[p:relation{relation:{relation}}]->(m)")
    void createCourseRelation(@Param("fromNode") String from, @Param("relation") String relation, @Param("toNode") String to);


}
